let stream = weex.requireModule('stream')

export default {
    methods: {
        UploadFile(url, fileUrls, callback) {
            let formData = new FormData()
            for (let i = 0; i < fileUrls.length; i++) {
                let fileUrl = fileUrls[i]
                let arr = fileUrl.split('/')
                if (arr.length <= 0) return
                let fileName = arr[arr.length - 1]
                let file = {uri: fileUrl, type: 'multipart/form-data', name: fileName}
                formData.append('file' + i, file)
            }
            return stream.fetch({
                method: 'POST',
                url: url,
                type: 'json',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                body: formData
            }, callback)
        }
    }
}